package com.googlecode.synccontacts.activity;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import com.googlecode.synccontacts.R;
import com.googlecode.synccontacts.dao.DbOpen;
import com.googlecode.synccontacts.interfaces.SocialNetwork;
import com.googlecode.synccontacts.listeners.SaveAccountListener;

/**
 * User: volkovma@inbox.ru
 * Date: 11.02.11
 * Save this accounts for soc.net.
 */
public class SettingActivity extends Activity {
    private DbOpen db;
    private Button saveB;
    private EditText login;
    private EditText pass;

    public static final int DIALOG_LOGGIN_ID = 0;
    public static final int DIALOG_PASS_ID = 1;
    public static final int DIALOG_ERROR_ID = 2;

    /**
     * Create form "Save accounts"
     *
     * @param savedInstanceState
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sett);
        saveB = (Button) findViewById(R.id.saveAccount);
        login = (EditText) findViewById(R.id.login);
        pass = (EditText) findViewById(R.id.pass);
        // Из входящих параметров получаем тир соцальной сети с которой работаетм
        int SocNetType = getIntent().getExtras().getInt(SocialNetwork.SOCIAL_NETWORK);
        saveB.setOnClickListener(new SaveAccountListener(SocNetType, this, login, pass));
    }

    /**
     * Предупреждающие сообщения
     *
     * @param id
     * @return
     */
    protected Dialog onCreateDialog(int id) {
        Dialog dialog = null;
        switch (id) {
            case DIALOG_LOGGIN_ID: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.loginDialogText)
                        .setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                dialog = builder.create();
            }
            break;
            case DIALOG_PASS_ID: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.passDialogText)
                        .setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                dialog = builder.create();
            }
            break;
            case DIALOG_ERROR_ID: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.errorSaveText)
                        .setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                dialog = builder.create();
            }
            break;
        }
        return dialog;

    }
}
